<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<script type="text/javascript">
    /**
     * 审核优惠券
     */
	<shiro:hasPermission name="back_gotoDiscountCouponPage_check">
    function auditDiscountCoupon() {
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            var id = selectedRow[0].discountCouponId;
            $("#btn_auditDiscountCoupon").attr("data-target", "#auditDiscountCouponModal");/**选中了记录后才可打开对应的模态框**/
            $.ajax({
                type: "POST",
                dataType: "JSON",
                url: "${basePath}/back/discountCoupon/getDiscountCouponObject.sjson",
                data: {discountCouponId: id},
                success: function (result) {
                    var data = JSON.parse(result.data);
                    /**隐藏域**/
                    $("#audit_discountCouponId").val(data.discountCouponId);
                    /**可见表单控件**/
                    $("#a_discountCouponName").empty().html(data.discountCouponName);
                    $("#a_discountCouponCode").empty().html(data.discountCouponCode);
                    $("#a_discountCouponAmount").empty().html(data.discountCouponAmount);
                    $("#a_discountCouponLowAmount").empty().html(data.discountCouponLowAmount);

                    if(data.beginTime!=""&&data.beginTime!=undefined){
                        $("#a_beginTime").empty().html(new Date(data.beginTime).Format("yyyy-MM-dd hh:mm:ss"));
                    }

                    if(data.expirationTime!=""&&data.expirationTime!=undefined){
                        $("#a_expirationTime").empty().html(new Date(data.expirationTime).Format("yyyy-MM-dd hh:mm:ss"));
                    }

                    $("#a_distributionCount").empty().html(data.distributionCount);

                    if(data.createTime!=""&&data.createTime!=undefined){
                        $("#a_createTime").empty().html(new Date(data.createTime).Format("yyyy-MM-dd hh:mm:ss"));
                    }

                    if(data.templateType==1){
                        $("#a_templateType").html("<font class='color_001'>模板一</font>");
                    }else if(data.templateType==2){
                        $("#a_templateType").html("<font class='color_001'>模板二</font>");
                    }else if(data.templateType==3){
                        $("#a_templateType").html("<font class='color_001'>模板三</font>");
                    }else if(data.templateType==4){
                        $("#a_templateType").html("<font class='color_001'>模板四</font>");
                    }

                    $("#isPass_" + data.isPass).attr("checked", "checked");
                }
            });
        }else {
            $("#btn_auditDiscountCoupon").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
    </shiro:hasPermission>

    /**
     * 表单异步提交
     */
    function submitForm_auditDiscountCoupon(){
        var options = {
            url: $("#form_auditDiscountCoupon").attr("action"),
            type : "post",
            dataType:"json",
            success : function(data) {
                if(data.success==true){
                    /** 先重置查询框的值**/
                    resetQueryForm();
                    /** 重新刷新列表数据**/
                    $("#tt").bootstrapTable('refresh');
                    /** 自动关闭弹出模态框窗口**/
                    $(".close").click();
                    showMsg("保存成功！");
                }else{
                    showMsg("保存失败！");
                }
            }
        };
        $("#form_auditDiscountCoupon").ajaxSubmit(options);
    }
</script>

<!--审核优惠券模态框（Modal） -->
<div class="modal fade" id="auditDiscountCouponModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel">审核优惠券</h5>
			</div>
			<div class="modal-body">
				<form id="form_auditDiscountCoupon" method="post" action="${basePath}/back/discountCoupon/auditDiscountCoupon.sjson">
					<input id="audit_discountCouponId" type="hidden" name="discountCouponId" value=""/>
					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px">优惠劵名称:</td>
							<td class="toleft_td" colspan="3">&nbsp;&nbsp;<span id="a_discountCouponName"></span></td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">优惠券码:</td>
							<td class="toleft_td" >&nbsp;&nbsp;<span id="a_discountCouponCode"></span></td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">优惠金额:</td>
							<td class="toleft_td">&nbsp;&nbsp;<span id="a_discountCouponAmount"></span></td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">优惠下限金额:</td>
							<td class="toleft_td">&nbsp;&nbsp;<span id="a_discountCouponLowAmount"></span></td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">开始时间:</td>
							<td class="toleft_td">&nbsp;&nbsp;<span id="a_beginTime"></span></td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">结束时间:</td>
							<td class="toleft_td">&nbsp;&nbsp;<span id="a_expirationTime"></span></td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">发放个数:</td>
							<td class="toleft_td">&nbsp;&nbsp;<span id="a_distributionCount"></span></td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">创建时间:</td>
							<td class="toleft_td">&nbsp;&nbsp;<span id="a_createTime"></span></td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">优惠券模板:</td>
							<td class="toleft_td" >&nbsp;&nbsp;<span id="a_templateType"></span></td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>是否通过审核:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<label class="checkbox-inline">
									<input type="radio" name="isPass" id="isPass_1" class="radioInput" value="1" checked="checked">&nbsp;待审核
								</label>
								<label class="checkbox-inline">
									<input type="radio" name="isPass" id="isPass_2" class="radioInput" value="2"  >&nbsp;审核通过
								</label>
								<label class="checkbox-inline">
									<input type="radio" name="isPass" id="isPass_3" class="radioInput" value="3"  >&nbsp;审核未通过
								</label>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary" onclick="submitForm_auditDiscountCoupon()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
